package com.amar.dtadmin.apidoc.extensions.storages;

import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.Service;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.project.Project;
import lombok.Data;
import org.jetbrains.annotations.NotNull;

/**
 * @author xiaoshiqiang
 * @since 2025/2/8
 */
@State(name = "DtAdminSettings", storages = {@Storage("DtAdminSettings.xml")})
@Service(Service.Level.PROJECT)
@Data
public final class DtAdminSettings implements PersistentStateComponent<DtAdminSettings> {
    /**
     * DtAdmin登陆用户
     */
    private String username;

    /**
     * DtAdmin登陆密码（密文）
     */
    private String password;

    /**
     * 项目编号
     */
    private String projectId;

    /**
     * 令牌
     */
    private String token;

    private String fullName;

    @Override
    public DtAdminSettings getState() {
        return this;
    }

    @Override
    public void loadState(@NotNull DtAdminSettings dtAdminSettings) {
        this.username = dtAdminSettings.getUsername();
        this.password = dtAdminSettings.getPassword();
        this.projectId = dtAdminSettings.getProjectId();
        this.token = dtAdminSettings.getToken();
        this.fullName = dtAdminSettings.getFullName();
    }

    public static DtAdminSettings getInstance(Project project) {
        return project.getService(DtAdminSettings.class);
    }
}
